import request from '@/utils/request'
import Qs from 'qs'

// 列表请求
export function getDict() {
  request({
    method: 'get',
    url: '/jcdSys/dict/list'
  }).then(res => {
    let dictObj = {} // 用来取值匹配的
    let checkDictObj = {} // 可以用来选择的
    res.data = [...res.data]
    res.data.forEach(item => {
      if (!dictObj[item.type]) dictObj[item.type] = {}
      if (!checkDictObj[item.type]) checkDictObj[item.type] = []
      let {
        label,
        type,
        value
      } = item
      dictObj[type][value] = label
      let dictVal;
      try {
        dictVal = JSON.parse(value)
      }catch {
        dictVal = value
      }
      checkDictObj[type].push({
        label,
        value: dictVal
      })
    })
    localStorage.setItem('dict', JSON.stringify(dictObj))
    localStorage.setItem('checkDict', JSON.stringify(checkDictObj))
  })
}
